﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;


namespace CarPark.Helper
{
    public static class MidLogin
    {

        /// <summary>
        /// 根据用户名和密码，判断用户有效性，如果用户有效则返回CR_OK，并赋值id，否则返回原因
        /// ，id=-1
        /// </summary>
        /// <param name="CKName">非空字符串</param>
        /// <param name="CKPassword">非空字符串</param>
        /// <returns></returns>
        public static string CheckLogInfo(string parkName , string userName, string userPassword, out int id)
        {
            id = 0;
            string sql = "select F_ID from TPark where F_Name = '"
                + parkName.Trim() + "'and F_Admin = '"
                + userName.Trim() + "' and F_AdminPass = '"
                + userPassword.Trim() + "'";
            DataTable dt = SQLHelper.GetDataTable(sql, null, null);
            if (null != dt && dt.Rows.Count > 0)
            {
                id = Convert.ToInt16(dt.Rows[0]["F_ID"]);
                return GlobalConst.CK_OK;
            }
            else
            {
                id = -1;
                return GlobalConst.CK_NOUSER;
            }
        }

        /// <summary>
        /// 返回当前数据库中所有的车库名称
        /// </summary>
        /// <returns></returns>
        public static List<string> GetCKNames()
        {
            List<string> ret = new List<string>();
            string sql = "select F_Name from TPark";
            DataTable dt = SQLHelper.GetDataTable(sql, null, null);
            if (null != dt)
            {
                foreach (DataRow dr in dt.Rows)
                    ret.Add(dr["F_Name"].ToString());
            }
            return ret;
        }

    }
}